<template>
  <div class="app-container">
    <el-form ref="form" :model="blog" label-width="80px" size="mini">
      <el-form-item label="标题">
        <el-input v-model="blog.blogTitle" />
      </el-form-item>
      <el-form-item label="分类">
        <el-select
          v-model="blog.blogType"
          clearable
          filterable
          placeholder="请选择"
          style="width: 100%"
        >
          <el-option
            v-for="type in typeList"
            :key="type.typeId"
            :label="type.typeName"
            :value="type.typeId"
          /> </el-select
      ></el-form-item>
      <el-form-item label="封面">
          <single-upload v-model="blog.blogImage"></single-upload>
      </el-form-item>
      <el-form-item label="内容">
        <tinymce v-model="blog.blogContent" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="blog.blogRemark" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="onSubmit">提交</el-button>
        <el-button size="mini" @click="closeAddDialog">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import Tinymce from "@/components/Tinymce/index";
import SingleUpload from '@/components/upload/singleUpload'

import blogApi from "@/api/blog";
import typeApi from "@/api/type";
import SingleUpload from '../../../../components/upload/singleUpload.vue';

export default {
  components: {
    Tinymce,
    SingleUpload
  },
  data() {
 
    SingleUpload   return {
      blog: {},
      typeList: null,
    };
  },
  methods: {
   //请求查询分类
     getTypeList(){
        typeApi.getTypeList().then(response =>{
          this.typeList = response.data.typeList
        })
     },

    onSubmit() {
      blogApi.saveBlog(this.blog).then((response) => {
         this.blog = {}
        this.$message({
          message: "保存成功",
          type: "success",
        });
        this.$emit('closeAddDialog','false')         //子组件向父组件发消息
       
      });
    },
    closeAddDialog() {
       this.$emit('closeAddDialog','false')         //子组件向父组件发消息
    },
  },
  created() {
    this.getTypeList()
  },
};
</script>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
